package com.pqc.tbk.service.mail;

import org.springframework.stereotype.Service;

import com.pqc.tbk.utils.Digest;
import com.pqc.tbk.utils.MailSender;
import com.pqc.tbk.utils.Settings;

@Service
public class MailServiceImpl implements MailService {

	@Override
	public boolean emailBind(final String email) {
		final Long time = System.currentTimeMillis();
		final String sign = Digest.sha1(email + time, null);
		final StringBuffer url = new StringBuffer(Settings.System.website
				+ "/user/home/emailVerify?");
		url.append("email=" + email);
		url.append("&t=" + time);
		url.append("&sign=" + sign);
		final StringBuffer content = new StringBuffer();
		content.append("您好，您只需要点击下面的链接接就可以完成邮箱的绑定，<br/>该链接接只可使用一次，并且只在24小时内有效。<br/>");
		content.append("<a href=\"" + url + "\" target=\"_blank\">" + url
				+ "</a><br/>");
		return MailSender.send(email, "邮箱绑定", content.toString());
	}

	@Override
	public void updatePwdEmail(final String email) {
		final Long time = System.currentTimeMillis();
		final String sign = Digest.sha1(email + time, null);
		final StringBuffer url = new StringBuffer(Settings.System.website
				+ "/user/home/forget_pwd?step=4");
		url.append("&email=" + email);
		url.append("&t=" + time);
		url.append("&sign=" + sign);
		final StringBuffer content = new StringBuffer();
		content.append("您好，点击下面链接可以修改密码。如果不是本人的操作， 请无视。<br/>该链接接只可使用一次，并且只在24小时内有效。<br/>");
		content.append("<a href=\"" + url + "\" target=\"_blank\">" + url
				+ "</a><br/>");
		MailSender.send(email, "修改密码", content.toString());

	}
}
